<?
    /**
     * Smarty plugin
     * @package Smarty
     * @subpackage plugins
     * @author Kulikov Alexey <a.kulikov@gmail.com>
     */


    /**
     * Smarty {load_user_data} function plugin
     *
     * Type:     function
     * Name:     load_user_data
     * Purpose:  Load the currently logged in user data
     *   @param array
     *   @param Smarty
     *
     * This smarty plugin can be talked to using the following
     * template parameters:
     *   
     *   * var (string) -- name of variable where to load the 
     *                     data tree to
     *                     >> default: user
     *
     * @return string
     */
    function smarty_function_load_user_data($params, &$smarty){
        global $db; // create a link to the database connection

        //pre-process parameters
        //variable name
        if(empty($params['var'])){
            $var = 'user';
        }else{
            $var = $params['var'];
        }
        
        //select the user data
        $data = $db->getRow("SELECT
                                user_access.id AS id,
                                user_access.login,
                                user_access.created,
                                user_data.fullname,
                                user_data.email
                             FROM user_access LEFT JOIN user_data ON user_access.id = user_data.uid
                             WHERE user_access.id = ".$_SESSION['admin']['id']);

        //give all this shit to smarty
        $smarty->assign($var,$data);
    }
?>